#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
  float principal, rate, payment;
  int term;
  char ch;

  while (1)
  {
    puts("\nEnter the loan amount:");
    scanf("%f", &principal);

    puts("\nEnter the rate:");
    scanf("%f", &rate);
    rate /= 100;
    rate /= 12;

    puts("\nEnter the loan duration in months: ");
    scanf("%d", &term);
    payment = (principal * rate) / (1 - pow((1 + rate), -term));
    printf("Your monthly payment will be $%.2f.\n", payment);
    puts("Do another (y or n)?");
    do
    {
      ch = getchar();
    } while (ch != 'n' && ch != 'y');

    if (ch == 'n')
    {
      break;
    }
  }

}
